

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>套餐设置</title>
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/metro/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/icon.css">
	<link href="../../rs/css/bootstrap.css" rel="stylesheet">
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="../../rs/js/jquery.cookie.js"></script>
	<script src="../../rs/js/common_qj.js"></script>
	<?php
  		require_once('login.php');
 	?>
</head>
<body >
<table id="table" class="easyui-datagrid"  style="width:100%;height:100%;padding: 10px;"
	   data-options="
			rownumbers:true,
			singleSelect:'false',
			method:'get' ,
			toolbar:'#easyui_toolbar',
  			fit:true,
			fitColumns:true">
	<thead>
	<tr>
		<th data-options="field:'ck',checkbox:true"></th>
		<th data-options="field:'prid2',align:'center',width:10,formatter:formatId">编号</th>
		<th data-options="field:'prname1',width:30" >名称</th>
		<th data-options="field:'prpriceout',width:30" >金额</th>
		<th data-options="field:'sl',width:30" >数量</th>
		<th data-options="field:'zyzh',width:20,align:'center',formatter:formatzh">自由组合</th>
		<th data-options="field:'notes',width:30" >备注</th>
		<th data-options="field:'bhcp',width:20,align:'center',formatter:formatbhcp" ></th>
	</tr>
	</thead>
</table>

<div id="easyui_toolbar" region="north" border="false"
	 style="height:45px;padding:5px 5px;">
	<div style="float: left;">
		<button id="shanchu" style="float:left; margin-right:5px; border-radius: 0px;height:34px "  class="btn" onclick="data_remove()" >
			<i class="glyphicon glyphicon-trash"></i>
		</button>
	</div>
	<div style="float: left;">
		<button id="xinzeng" type="button" style="float:left;margin-left:5px;  border-radius: 0px;" class="btn " onclick="open_modal()"  >
			<i class="glyphicon glyphicon-plus"></i> 新增
		</button>
	</div>
	<div id="tb" class="input-group" style="float: right; margin-right: 10px;width:350px">
		<input type="text" class="form-control" id="searchtext" placeholder="输入搜索关键字" value="">
		<div class="input-group-btn">
			<button type="button" class="btn btn-white dropdown-toggle" onclick="do_search()" style="border-radius: 0px;">
				搜索
			</button>
		</div>
	</div>
</div>

<?php
require 'chp.php';
?>

<!--//新增产品名称弹框-->
<!-- <div id="easyui_toolbar_xz" region="north" border="false"
	 style="height: 45px;padding: 5px 5px; ">
	<div class="input-group " style="float: left; width:250px">
				<span class="input-group-btn">
					<button style="margin-right: -2px;height:34px;border: 1px solid #e5e6e7;font-size: 14px" type="button" class="btn btn-sm ">类别</button>
				</span>
		<select class="form-control" id="get_lb" >
			<option value='all'>全部分类</option>
		</select>
	</div>
	<div  class="input-group" style="float: right; margin-right: 10px;width:300px">
		<input type="text" class="form-control" id="searchtext_xzcp" placeholder="输入搜索关键字" value="">
		<div class="input-group-btn">
			<button type="button" class="btn  dropdown-toggle" onclick="f_sheard_xz('tc')" style="height:34px;border-radius: 0px;">
				搜索
			</button>
		</div>
	</div>
</div>
<div style="display: none" id="open_table_xz">
	<div id="edit_table_xz">
		<table id="table_xz" class="easyui-datagrid"  style="width:100%;height:520px;padding: 10px;"
			   data-options="
			rownumbers:true,
			singleSelect:'false',
			toolbar:'#easyui_toolbar_xz',
			method:'get' ,
			height: 250,
			fit:false,
			fitColumns:true
	        ">
			<thead>
			<tr>
				<th data-options="field:'prid',width:20,align:'center'">产品编号</th>
				<th data-options="field:'prname1',width:50,align:'center'">产品名称</th>
				<th data-options="field:'prpriceout',width:20,align:'left'">售价</th>
				<th data-options="field:'xz',width:15,align:'center',formatter:format_xz"></th>
			</tr>
			</thead>
		</table>

	</div>
</div> -->
<!--//新增产品名称弹框-->




<!--//选择包含产品弹框-->
<div id="easyui_toolbar_bhcp" region="north" border="false"
	 style="height: 45px;padding: 5px 5px; ">
	<div style="float: left;">
		<button style="float:left; margin-right:5px; border-radius: 0px; "  class="btn" onclick="data_remove_bhcp()" >
			<i class="glyphicon glyphicon-trash"></i>
		</button>
	</div>
	<div  class="input-group" style="float: right; margin-right: 10px;width:80px">

		<div class="input-group-btn">
			<button type="button" class="btn  dropdown-toggle" onclick="f_sheard_xz('cp')" style="height:34px;border-radius: 0px;">
				<i class="glyphicon glyphicon-plus"></i> 选择产品
			</button>
		</div>
		<div class="input-group-btn">
			<button type="button" style="float:left;margin-left:5px;  border-radius: 0px;" class="btn " onclick="table_bhcp_save()"  >
				 保存
			</button>
		</div>
	</div>
</div>
<div style="display: none" id="open_table_bhcp">
	<div id="edit_table_bhcp">
		<table id="table_bhcp" class="easyui-datagrid"  style="width:100%;height:520px;padding: 10px;"
			   data-options="
					rownumbers:true,
					singleSelect:'false',
					toolbar:'#easyui_toolbar_bhcp',
					method:'get' ,
					height: 250,
					fit:false,
					fitColumns:true
					">
			<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'grid',width:10,editor:'text'" >互斥组</th>
				<th data-options="field:'prname1',width:20" >品名</th>
				<th data-options="field:'je',width:20,editor:'text'" >金额</th>
				<th data-options="field:'sl',width:10,editor:'text'" >数量</th>
				<th data-options="field:'zds',width:10,editor:'text'" >最大数</th>
				<th data-options="field:'s',width:20,align:'center',editor:{type:'checkbox',options:{on:'Y',off:'N'}}" >默认选中Y/N</th>
			</tr>
			</thead>
		</table>

	</div>
</div>







<!--//新增的弹框页面-->
<div style="display: none" id="open_xz">
	<form id="edit_xz">
		<div class="input-group" style="padding: 20px 20px 15px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">产品</button>
			</div>
			<input type="text" class="form-control" name="prname1" id="searchtext_xz" placeholder="输入搜索关键字"  >
					<span class="input-group-btn">
						<button type="button"  onclick="f_sheard_xz('tc')"  style="border-radius: 0px; height: 34px;"   class="btn btn-white">
							<i class="glyphicon glyphicon-zoom-in"></i>
						</button>
				</span>
		</div>
		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">数量</button>
			</div>
			<input type="text" class="form-control "   name="sl"  id="sl"  >
		</div>
		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">金额</button>
			</div>
			<input type="text" class="form-control "   name="prpriceout"  id="prpriceout"  >
		</div>

		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">备注</button>
			</div>
			<input type="text" class="form-control "   name="notes" id="notes">
		</div>

		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<label   class="btn btn-white dropdown-toggle" style="font-weight: 700;padding:0px">自由组合：
					<input name="zyzh" style="vertical-align:middle;width:15px;height:15px" type='checkbox'  checked='true'>
				</label>
			</div>
			<div style="padding: 8px 12px;font-weight: 600;">
				<!--是: <input type="radio" checked="checked" name="s" value="Y" />
				否: <input type="radio" name="s" value="N" />-->

			</div>
		</div>


		<div class="lay_foot">
			<button type="reset" id="reset_xz" style="display:none ">reset</button>
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #e2e2e2;" onclick="layer.closeAll()">返回
			</button>
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #f54141;color: white;float: right" id="save_do">保存
			</button>
		</div>
	</form>
</div>
<!--//新增的弹框页面-->

<!--//套餐修改的弹框页面-->
<div style="display: none" id="open_xg">
	<form id="edit_xg">
		<div class="input-group" style="padding: 20px 20px 15px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">名称</button>
			</div>
			<input type="text" class="form-control "   name="prname1_xg" readonly>
		</div>
		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">数量</button>
			</div>
			<input type="text" class="form-control "   name="sl_xg"    >
		</div>
		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">金额</button>
			</div>
			<input type="text" class="form-control "   name="prpriceout_xg"   >
		</div>

		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<button style="margin-right: -2px; height:34px" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">备注</button>
			</div>
			<input type="text" class="form-control "   name="notes_xg" >
		</div>

		<div class="input-group" style="padding: 0px 20px 10px 20px;">
			<div class="input-group-btn">
				<label   class="btn btn-white dropdown-toggle" style="font-weight: 700;padding:0px">自由组合：
					<input style="vertical-align:middle;width:15px;height:15px" type='checkbox' name="zyzh_xg" checked='true'>
				</label>
			</div>
			<div style="padding: 8px 12px;font-weight: 600;">
			</div>
		</div>


		<div class="lay_foot">
			<button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #e2e2e2;" onclick="layer.closeAll()">返回
			</button>
			<button id="G_edit" type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
					style="background-color: #f54141;color: white;float: right" onclick="save_edit(rowindex_edit,rowdata_edit)" >保存
			</button>
		</div>
	</form>
</div>
<!--//套餐修改的弹框页面-->


<!--页面加载缓冲图标-->
<div id='loadingDiv' style="position:absolute;z-index:1000;top:0px; left:0px;
	width:100%;height:100%;background:white;text-align: center;">
	<h1 style="top: 30%; position: relative;">
		<img src="../../rs/img/loading-2.gif" /><br>
	</h1>
</div>
<script>

	/*页面加载缓冲*/
	function closeLoading() {
		$("#loadingDiv").fadeOut("normal", function () {
			$(this).remove();
		});
	}
	var no;
	$.parser.onComplete = function () {
		if (no) clearTimeout(no);
		no = setTimeout(closeLoading, 1000);
	}
	/*页面加载缓冲*/
	/*从coolie获取sign的值*/
	var sign = URLencode($.cookie('sign'));
	$(function(){
		if(sign==="undefined"){
			window.location.href = "login.html";
		}
		get_lb();
		f_sheard();
    sqx();//判断小权限
		var getdata;
		var rowindex_edit;//套餐修改的行
		var rowdata_edit;//套餐修改的数据
	});

	//判断用户权限&加载包含产品数据
	function f_sheard(){
		$.ajax({
			type: "post",
			url:G_url+'metc/see?sign='+sign,
			data: 'sign=' + sign,
			dataType: "json",
			success: function (result){
				getdata=result;
				if (result.ok) {
					$('#table').datagrid({
						data: result.data
					});
				}else{
						layer.msg(result.msg);
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}



	/*保存操作*/
	var prid;
	var prname1;
	$("#save_do").on("click",function(){
		var prpriceout=$('#prpriceout').val();
		var sl=$('#sl').val();
		var notes=$('#notes').val();
		var zyzh=$('input[name="zyzh"]').prop("checked");
		var s_xz;
		if(zyzh==true){
			s_xz="Y"
		}else if(zyzh==false){
			s_xz="N"
		}
		if (prid==undefined)
		{
			layer.msg("请搜索您要选择的商品！");
		}else{
			$.ajax({
				type: "post",
				url:G_url+'metc/save?sign='+sign,
				data:"prid="+prid+"&prpriceout="+prpriceout+"&sl="+sl+"&notes="+notes+"&zyzh="+s_xz,
				dataType: "json",
				success: function (result){
					if (result.ok){
						$('#table').datagrid('appendRow',{
							prid2:prid,
							prname1:prname1,
							prpriceout:prpriceout,
							sl:sl,
							notes:notes,
							zyzh:zyzh
						});
						layer.msg(result.msg);
					} else {
						layer.msg(result.msg);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
				}
			});
		}

	});



	//修改套餐保存
	function save_edit(index,data){
		var prid2=data.prid2;
	//  var prname1=$('input[name="prname1_xg"]').val();
	 var sl=$('input[name="sl_xg"]').val();
	 var prpriceout=$('input[name="prpriceout_xg"]').val();
	 var notes=$('input[name="notes_xg"]').val();
	 var zyzh=$('input[name="zyzh_xg"]').prop("checked");
	 var s_xz;
	 if(zyzh==true){
		 s_xz="Y"
	 }else if(zyzh==false){
		 s_xz="N"
	 }

	 $.ajax({
			type: "post",
			url:G_url+'metc/save?sign='+sign,
			data:"prid="+prid2+"&prpriceout="+prpriceout+"&sl="+sl+"&notes="+notes+"&zyzh="+s_xz,
			dataType: "json",
			success: function (result){
				if (result.ok){
					$('#table').datagrid('updateRow',{
								index:index,
								row: {
									prid2:prid,
									prname1:prname1,
									prpriceout:prpriceout,
									sl:sl,
									notes:notes,
									zyzh:zyzh
										}
					});
					layer.msg(result.msg);
				} else {
					layer.msg(result.msg);
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});

	}


	/*删除操作*/
	function data_remove(){
		var rows = $('#table').datagrid('getSelections');
		var row = $('#table').datagrid('getSelected');
		var rowIndex = $('#table').datagrid('getRowIndex', row);
		if(row.length!=0){
			layer.msg('确定删除吗？', {
				time:0,
				btn: ['确定', '取消'] //按钮
				,yes: function do_remove1() {
					var prid2s = $.map(rows, function (row) {
						return row.prid2
					});
					$.ajax({
						type: "post",
						url:G_url+'metc/del?sign='+sign,
						data:"&prid2=" + prid2s,
						dataType: "json",
						success: function (result) {
							if (result.ok) {
								layer.closeAll();
								$('#table').datagrid('deleteRow', rowIndex);
								layer.msg(result.msg);

							} else {
								layer.msg(result.msg);
							}
						},
						error: function (XMLHttpRequest, textStatus, errorThrown) {

						}
					});
				}
			});
		}else{
			layer.msg("请先选择！");
		}
	}
	//删除操作



	/*删除包含产品*/
	function data_remove_bhcp(){
		var rows = $('#table_bhcp').datagrid('getSelections');
		var row = $('#table_bhcp').datagrid('getSelected');
		var rowIndex = $('#table_bhcp').datagrid('getRowIndex', row);
		if(rows.length!=0){
			var del_bhcp=layer.msg('确定删除吗？', {
						time:0,
						btn: ['确定', '取消'] //按钮
						,yes: function do_remove() {
							var prpriceout = $.map(rows, function (row) {
								return row.prpriceout;
							});
							layer.close(del_bhcp);
							$('#table_bhcp').datagrid('deleteRow', rowIndex);
						}
					}
			);
		}else{
			layer.msg("请先选择！");
		}
	}
	//删除包含产品










	// 产品搜索操作
	$('#searchtext').bind('keypress',function(event){
		if(event.keyCode == "13") {
			do_search();
		}
	});

//产品搜索

	$('#cp_gjc').bind('keydown',function(event){
		if(event.keyCode ==13) {
			search_cp();
		}
	});

	//搜索产品
	function do_search(){
		var gjc=$('#searchtext').val(); //搜索关键词
		if(gjc==""){
			$('#table').datagrid({
				data: getdata.data
			});
		}else{
			var newdata=[];
			for(var i=0;i<getdata.data.length;i++){
				str=transform(getdata.data[i]).join(',');
				row=str.indexOf(gjc);
				if(row>=0){
					newdata.push(getdata.data[i]);
				}
			}
			$('#table').datagrid({
				data: newdata
			});
		}
	}

	var gjc;
	function transform(obj){
		var arr = [];
		for(var item in obj){
			arr.push(obj[item]);
		}
		return arr;
	}



	function open_modal(){
    sqx_save_tcsz("新增");
		$("#open_xz").show();
		$('#reset_xz').click();
		table=layer.open({
			title: "新增",
			type: 1,
      offset: 'rb',
      area: ['40%', '100%'], //宽高
      shadeClose: true,
			content: $('#edit_xz')
		});
	}


	//弹出选择产品表格
	function open_table_modal(){
		$("#open_table_xz").show();
		$('#reset_xz').click();
		table_xz=layer.open({
			title: "选择产品",
			type: 1,
      offset: 'rb',
      area: ['60%', '100%'], //宽高
      shadeClose: true,
			content: $('#edit_table_xz')
		});
	}



	var rowindex;  //获取选择的行
	var getprid;  //获取所选行的prid
	function open_edit(r,data){
    sqx_save_tcsz("修改");

			rowindex_edit=r;
			rowdata_edit=data;
			$("#open_xg").show();
			$('input[name="prname1_xg"]').val(data.prname1);
			$('input[name="sl_xg"]').val(data.sl);
			$('input[name="prpriceout_xg"]').val(data.prpriceout);
			$('input[name="notes_xg"]').val(data.notes);
		 if(data.zyzh=="N"){
			 $('input[name="zyzh_xg"]').attr('checked',false);
		 }else{
			 $('input[name="zyzh_xg"]').attr('checked',true);
		 }
			table=layer.open({
				title: "套餐修改",
				type: 1,
        offset: 'rb',

        area: ['40%', '100%'], //宽高
        shadeClose: true,
				content: $('#edit_xg')
			});

	}


	// 弹出套餐包含产品的弹框
	var cs_prid2;//套餐保存包含产品时候传入一个prid2值
	function open_bhcp(rowData){
		$("#open_table_bhcp").show();
		var prid=rowData.prid;
		var prid2=rowData.prid2;
	  cs_prid2=prid2;
		f_sheard_bhcp(prid2);
		table_bhcp=layer.open({
			title: "选择包含产品",
			type: 1,
      offset: 'rb',
      
      
      area: ['60%', '100%'], //宽高
      shadeClose: true,
			content: $('#edit_table_bhcp')
		});
	}


	//包含产品的数据加载
	function f_sheard_bhcp(prid2){
		$.ajax({
			type: "post",
			url:G_url+'metc/see2?sign='+sign,
			data:'prid='+prid2,
			dataType: "json",
			success: function (result){
				$('#table_bhcp').datagrid({
					data: result.data
				});
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}






	//新增表格的的选择
	function format_xz(value,rowData,rowIndex){
		return "<button style='height: 24px;line-height: 24px;padding: 0px 6px;border-radius: 0px;background-color: #23c6c8;color: #fff;' class='btn' onclick='add_sp("+JSON.stringify(rowData)+","+'canshu'+");'>选择</button>";
	}


	function formatId(value,rowData,rowIndex){
		return "<a href='javascript:void(0)' onclick='open_edit("+rowIndex+","+JSON.stringify(rowData)+");'>"+value+"</a>";
	}
	function formatbhcp(value,rowData,rowIndex){
		return "<a href='javascript:void(0)' onclick='open_bhcp("+JSON.stringify(rowData)+");'>"+"包含产品"+"</a>";
	}


	$('#searchtext_xz').bind('keydown',function(event){
		if(event.keyCode ==13) {
			f_sheard_xz('tc');
		}
	});

	//判断自由组合
	function formatzh(value,rowData,rowIndex){
		if(value=="Y"){
			return "<span  >是</span>";
		}else{
			return "<span >否</span>";
		}
	}


	function format_mrxz(value,rowData,rowIndex){
		if(value=="Y"){
			return "<input type='checkbox'  checked='true'>";
		}else{
			return "<input type='checkbox'>";
		}
	}




	//搜索结果的数据加载
	var canshu;
	function f_sheard_xz(aaa){
		canshu=aaa;
		var gjc_xz=$('#searchtext_xz').val(); //搜索关键词
		$.ajax({
			type: "post",
			url:G_url+'prsp/getslpr?sign='+sign+'&s='+gjc_xz,
			data:'',
			dataType: "json",
			success: function (result){
				if(result.rows.length==1){
					$("input[name='prname1']").val(result.rows[0].prname1);
					$('#dj').val(result.rows[0].prpriceout);
					prid=result.rows[0].prid;
					prname1=result.rows[0].prname1;
				}else if(result.rows.length==0){
					layer.msg("数据为空!");
				}else{
					open_table_modal();
					/*layer.close(table);*/
					$('#table_xz').datagrid({
						data: result.rows
					});
				}


			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}

	//选择产品
	function add_sp(rowdata,bb){
		prid=rowdata.prid;
		if(bb=="tc"){
			$("input[name='prname1']").val(rowdata.prname1);
			$('#prpriceout').val(rowdata.prpriceout);
			$('#sl').val(1);
			prid=rowdata.prid;
			prname1=rowdata.prname1;
			layer.close(table_xz);
		}else if(bb=="cp"){


			$('#table_bhcp').datagrid('appendRow',{
				prid:prid,
				prid2:cs_prid2,
				lb:rowdata.prsort,
				grid:rowdata.prsort,
				prname1:rowdata.prname1,
				je:rowdata.prpriceout,
				sl:"1.00",
				zds:"1.00",
				s:"N"
			});
			layer.close(table_xz);
		}
	}



	//产品搜索
	function search_cp(){
		var cp_gjc=$('#cp_gjc').val(); //搜索关键词
		$.ajax({
			type: "post",
			url:G_url+'prsp/getslpr?sign='+sign+'&s='+cp_gjc,
			data:'',
			dataType: "json",
			success: function (result){
				$('#table_xz').datagrid({
					 data: result.rows
				 });
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}






	//获取类别
	function get_lb(){
		$.ajax({
			type: "post",
			url:G_url+'slst/see?'+sign,
			data:'sign='+sign,
			dataType: "json",
			success: function (result){
				var ff = result.data;
				var html = '';
				$.each(ff, function (a, b) {//直接取出json的prolist做each循环.
					html += "<option value='"+b.p_sort+"'>" + b.p_sort_name + "</option>";//拼接字符串.
				});
				$("#get_lb").append(html);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}

	$('#get_lb').change(function(){
		var get_lb=$(this).children('option:selected').val();//这就是selected的值
		$.ajax({
			type: "post",
			url:G_url+'prsp/getslpr?sign='+sign,
			data:'lb='+get_lb,
			dataType: "json",
			success: function (result){
				if (result.ok){
					$('#table_xz').datagrid({
						 data: result.rows
					 });
				} else {
					layer.msg(result.msg);
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	})


//保存包含产品
	function table_bhcp_save(){

    //$('#table_bhcp').datagrid().datagrid('enableCellEditing');
  //  $('#table_bhcp').datagrid('endEdit', editIndex);
  //结束单元格编辑
    $('#table_bhcp').datagrid('acceptChanges');

		var senddata = $('#table_bhcp').datagrid('getData');
		var data=senddata.rows;
		if(data.length!=0){
		$.ajax({
			type: "post",
			url:G_url+'metc/savezh?sign='+sign,
			data:JSON.stringify(data),
			dataType: "json",
			success: function (result){
				if (result.ok){
					layer.msg(result.msg);
				} else {
					layer.msg(result.msg);
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
}else{
	$.ajax({
 	 type: "post",
 	 url:G_url+'metc/savezh?sign='+sign,
 	 data:"&prid2=" + cs_prid2,
 	 dataType: "json",
 	 success: function (result){
 		 if (result.ok){
 			 layer.msg(result.msg);
 		 } else {
 			 layer.msg(result.msg);
 		 }
 	 },
 	 error: function (XMLHttpRequest, textStatus, errorThrown) {
 	 }
  });
}


	}



	$.extend($.fn.datagrid.methods, {
		editCell: function(jq,param){
			return jq.each(function(){
				var opts = $(this).datagrid('options');
				var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field){
						col.editor = null;
					}
				}
				$(this).datagrid('beginEdit', param.index);
				// alert(param.index);
				var ed = $(this).datagrid('getEditor', param);
				if (ed){
					if ($(ed.target).hasClass('textbox-f')){
						$(ed.target).textbox('textbox').focus();

					} else {
						var mydata = $('#table_bhcp').datagrid('getData');
						console.log(mydata.rows[param.index]);//编辑行的数据
						var cudata=mydata.rows[param.index];
						for(var i=0;i<mydata.rows.length;i++){
							if(cudata.grid==mydata.rows[i].grid){
								cudata=mydata.rows[param.index];

								$('#table_bhcp').datagrid('updateRow',{
											index:i,
											row: {
												sl: cudata.sl
													}
								});
							}
						}

						$(ed.target).focus();
					}
				}
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor = col.editor1;
				}
			});
		},
		enableCellEditing: function(jq){
			return jq.each(function(){
				var dg = $(this);
				var opts = dg.datagrid('options');
				opts.oldOnClickCell = opts.onClickCell;
				opts.onClickCell = function(index, field){
					if (opts.editIndex != undefined){


						if (dg.datagrid('validateRow', opts.editIndex)){
							dg.datagrid('endEdit', opts.editIndex);
							opts.editIndex = undefined;
						} else {
							return;
						}
					}
					dg.datagrid('selectRow', index).datagrid('editCell', {
						index: index,
						field: field
					});
					opts.editIndex = index;
					opts.oldOnClickCell.call(this, index, field);
				}
			});
		},

	});

	$(function(){
		$('#table_bhcp').datagrid().datagrid('enableCellEditing');
	})



	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#table_bhcp').datagrid('validateRow', editIndex)){
			$('#table_bhcp').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}


	/*$(document).on("click.datagrid", function(e) { //点击datagrid空白区域，结束编辑
		/!*if (_index >= 0) {
			$(document).off("click.datagrid");
			$(_target).datagrid('endCellEditExt', _index); //结束编辑单元格
		}*!/
		/!*$(document).off("click.datagrid");*!/
		endEditing();
		alert("sss");
	});*/




</script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/md5.js"></script>
</body>
</html>
